package fct.mpc.snipehunter;

import java.util.List;

import android.app.ListActivity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import fct.mpc.utils.Stat;
import fct.mpc.utils.StatManager;

public class SnipeHunterStatsActivity extends ListActivity {

	// Debugging
	//private static final String TAG = "StatsActivity";
	//private static final boolean D = true;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.stats);

		StatAdapter adapter = new StatAdapter(this,
				android.R.layout.simple_list_item_1, R.id.statName);
		setListAdapter(adapter);
		
		getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
	}
	
	@Override
	protected void onDestroy()
	{
		getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
		
		super.onDestroy();
	}

	private class StatAdapter extends ArrayAdapter<Stat> {

		public StatAdapter(Context context, int resource, int textViewResourceId) {
			super(context, resource, textViewResourceId);
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {

			LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
			View row = inflater.inflate(R.layout.stat_item, parent, false);

			TextView tv_name = (TextView) row.findViewById(R.id.statName);
			TextView tv_value = (TextView) row.findViewById(R.id.statValue);

			List<Stat> stats = StatManager.getAllStats();

			tv_name.setText(stats.get(position).getName());
			tv_value.setText(stats.get(position).getValue());
			return super.getView(position, convertView, parent);
		}

	}

	@Override
	protected void onResume() {
		super.onResume();
	}

	@Override
	protected void onPause() {
		super.onPause();
	}
}
